﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Conditions;

public partial class Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        DBConditions Conds = new DBConditions();
        Conds.add("Username", Login1.UserName.Trim());
        ketnoicsdl Conn = new ketnoicsdl();
        Conn.open();
        DataTable Tb = Conn.select("select * from nv where (where)", "(where)", Conds);
        if (Tb.Rows.Count != 1)
        {
            e.Authenticated = false;
            Conn.close();
            return;
        }
        string pass = Login1.Password;
        if (pass == Tb.Rows[0]["Pass"].ToString())
        {
            e.Authenticated = true;
            //Ghi lại token
            string token = DateTime.Now.ToString("yyyyMMddHHmmssff");
            Session["token"] = token;
            Session["username"] = Login1.UserName.Trim();
        }
        else
        {
            e.Authenticated = false;
            //Ghi lại số lần sai
        }
        Conn.close();
    }
}
